package homework5;

import java.util.Objects;

/**
 * 需求：使用LinkedHashMap保存学生对象，及其对应的家庭住址；要求：
 *
 * 1. 学生具有学号、姓名和成绩三个属性；
 * 2. 其中，学号不能重复；
 *
 * 思路：
 *
 * - 要重写hashCode和equals方法，学号不能重复，只要选中学号即可。
 */
public class Student {
    private int studyNum;
    private String name;
    private Integer score;

    @Override
    public String toString() {
        return "Student{" +
                "studyNum='" + studyNum + '\'' +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Student student = (Student) o;
        return Objects.equals(studyNum, student.studyNum) && Objects.equals(name, student.name) && Objects.equals(score, student.score);
    }

    @Override
    public int hashCode() {
        return Objects.hash(studyNum, name, score);
    }

    public Student() {
    }

    public Student(int studyNum, String name, Integer score) {
        this.studyNum = studyNum;
        this.name = name;
        this.score = score;
    }

    public int getStudyNum() {
        return studyNum;
    }

    public void setStudyNum(int studyNum) {
        this.studyNum = studyNum;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }
}
